<?php

 /**
  * @package JooS
  * @subpackage PHPackager
  */

  require_once "JooS/PHPackager/Relation/Abstract.php";
  
  require_once "JooS/PHPackager/Relation/Php/Interface.php";

  class JooS_PHPackager_Relation_IniGet extends JooS_PHPackager_Relation_Abstract implements JooS_PHPackager_Relation_Php_Interface {
    /**
     * @return JooS_PHPackager_Relation_IniGet
     */
    public static function newInstance() {
      return new self();
    }

    /**
     * @return bool
     */
    public function exists() {
      $iniValue = ini_get($this->getName());
      $value = $this->getValue();

      if (is_array($value)) {
        $exists = in_array($iniValue, $value);
      }
      else {
        $exists = $iniValue == $value;
      }

      return $exists;
    }

    private $_value = null;

    /**
     * @param string $value
     * @return JooS_PHPackager_Relation_IniGet
     */
    public function setValue($value) {
      $this->_value = $value;

      return $this;
    }

    /**
     * @return string
     */
    public function getValue() {
      return $this->_value;
    }

    /**
     * @return string
     */
    public function getMessage() {
      $value = $this->getValue();
      if (is_array($value)) {
        foreach ($value as $k => $v)
          $value[$k] = "'$v'";

        $strValue = "in (" . implode(", ", $value) . ")";
      }

      return "ini_get('" . $this->getName() . "') must be " . (is_array($value) ? "in array(" . implode(", ", $value) . ")" : "== " . $value);
    }
  }
